/**
 * @param {number[]} nums
 * @return {number}
 */
 var maxRotateFunction = function(nums) {
  const sum = nums.reduce((a, b, i) => a + b * i) - nums[0];
  let ct = 0;
  const total = nums.reduce((a, b) => a + b);
  let ret = sum;
  let curr = sum;
  const l = nums.length;
  for(let i = 1; i < nums.length; i++) {
      curr += total;
      curr -= l * nums[l - i]; 
      ret = Math.max(ret, curr);
  }
  return ret;
};